package com.controller.jsp;

import com.service.EmployeeServiceImpl;
import com.utils.PageInfoEx;
import entity.EmpEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/page2")
public class PageServlet2 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pageNumString = req.getParameter("pagenum");
        String pageSizeString = req.getParameter("pagesize");

        int pageNum = pageNumString == null || pageNumString.isEmpty()
                ? 1 : Integer.parseInt(pageNumString);
        int pageSize = pageSizeString == null || pageSizeString.isEmpty()
                ? 4 : Integer.parseInt(pageSizeString);

        EmployeeServiceImpl employeeService = new EmployeeServiceImpl();
        List<EmpEntity> list = employeeService.getAllByPageHelper(pageNum, pageSize);
        PageInfoEx<EmpEntity> pageInfoEx = new PageInfoEx<>(list);
        req.setAttribute("list", pageInfoEx);
        req.getRequestDispatcher("/WEB-INF/index2.jsp").forward(req, resp);
    }
}
